﻿using System;
using Abp.Dependency;
using Abp.Modules;
using Castle.MicroKernel.Registration;
using MgSoft.K3Cloud.WebApi.Dto;
using MgSoft.K3Cloud.WebApi.Services;

namespace MgSoft.K3Cloud.WebApi.Abp
{
    public class MgSoftK3CloudWebApiAbpModule : AbpModule
    {
        public MgSoftK3CloudWebApiAbpModule()
        {
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void PreInitialize()
        {
            Type basetype = typeof(IApi);
            //IocManager.IocContainer.Register(
            //    Classes.FromAssembly(typeof(IApi).Assembly)
            //    .BasedOn<IApi>());

            IocManager.IocContainer.Register(Classes.FromAssembly(typeof(IApi).Assembly)
                .BasedOn<IApi>()
                .WithService
                .FromInterface());

            //typeof(IApi).Assembly)
            //    .Where(t => basetype.IsAssignableFrom(t) && t.IsClass)
            //    .AsImplementedInterfaces()
            //    .InstancePerLifetimeScope();

            IocManager.Register<ILoginServices, LoginServices>(DependencyLifeStyle.Transient);

            IocManager.IocContainer.Register(Castle.MicroKernel.Registration.Component.For<ApiServerInfo>());
            //    ApiServerInfo
            //   OnActivating(p =>
            //   {
            //       ApiServerInfo apiServerInfo = new ApiServerInfo();
            //       cfgAction.Invoke(apiServerInfo);
            //       p.ReplaceInstance(apiServerInfo);
            //   });

            //containerBuilder.RegisterType(this.GetType()).OnActivating(p => p.ReplaceInstance(this));
        }
    }
}
